<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\file\FileInput;
use common\models\member\Member;
use common\models\modelled\Modelled;
/* @var $this yii\web\View */
/* @var $model common\models\member\Member */
/* @var $form yii\widgets\ActiveForm */
$modelled = Modelled::find()->andWhere(['category'=>'会员管理'])->asArray()->all();
?>
<style>
.kv-file-content img{ width: 100%!important; }
</style>
<script type="text/javascript" src="<?= yii::getAlias('@web');?>/js/jquery.js"></script>
<script type="text/javascript" src="<?= yii::getAlias('@web');?>/js/PCASClass.js"></script>

<script type="text/javascript" src="<?= yii::getAlias('@web');?>/js/hDate.js"></script>
<script type="text/javascript" src="<?= yii::getAlias('@web');?>/js/hDate.js"></script>
<div class="member-form">

    <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data'],'id'=>'subform']); ?>

    <div class="row">
        <div class="col-md-2">
            <?= $form->field($model, 'username')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'phone')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'xingming')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-3">
            <?= $form->field($model, 'email')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-3">
            <?= $form->field($model, 'work')->textInput(['maxlength' => true]) ?>
        </div>

    </div>
    <div class="row">
        <div class="col-md-6">
            <?= $form->field($model, 'password')->passwordInput(['maxlength' => 255])->label('密码') ?>
        </div>
        <div class="col-md-6">
            <?= $form->field($model, 'repassword')->passwordInput(['maxlength' => 255])->label('确认密码') ?>
        </div>
    </div>
    <div class="row">
        <div class="col-md-6">
            <?= $form->field($model, 'company')->textInput(['maxlength' => true]) ?>

        </div>

        <div class="col-md-6">
            <div class="form-group field-thirdproduct-birthday required" >
                企业所在地<br/>
                <select id="province" name="loc_province" value="<?= $model['loc_province'] ?>" style="width:135px;"></select>
                <select id="city" name="loc_city" value="<?= $model['loc_city'] ?>" style="width:135px; margin-left: 10px"></select>
                <select id="area" name="loc_town" value="<?= $model['loc_town'] ?>" style="width:135px;margin-left: 10px"></select>
            </div>
        </div>

    </div>

    <div class="row">
        <div class="col-md-6">
            <?php
            if(isset(json_decode($model->faceimg)->newname)){
                $img = json_decode($model->faceimg)->newname;
            }else{

                $img = $model->faceimg;
            }
            $siteRoot = Yii::$app->params['memberimg'];
            echo '<label class="control-label">照片(格式:98**98,以像在图片中部的半身像为佳)</label>;';
            echo FileInput::widget([
                'model' => $model,
                'attribute' => 'faceimg',
                'options' => ['accept' => 'image/*'],
                'pluginOptions' => [
                    'uploadExtraData' => [
                        'album_id' => 20,
                        'cat_id' => 'Nature'
                    ],
                    'initialPreview'=>[
                        !empty($img)?Html::img(Yii::$app->params['memberimg'].$img):null,
                    ],
                    'initialCaption'=> $img,
                    'maxFileCount' => 10,
                    "showUpload"=> false,
                ]
            ]);
            ?>
        </div>
    </div>
    <div class="row">
        <div class="col-md-3">
            <?= $form->field($model, 'address')->textInput(['maxlength' => 255]) ?>
        </div>
        <div class="col-md-3">
            <?= $form->field($model, 'farentel')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-3">
            <?= $form->field($model, 'grnum')->textInput(['maxlength' => 255]) ?>
        </div>
        <div class="col-md-3">
            <?= $form->field($model, 'zhucezj')->textInput(['maxlength' => 255]) ?>
        </div>
    </div>
    <div class="row">
        <div class="col-md-4">
            <?= $form->field($model, 'faren')->textInput(['maxlength' => 255]) ?>
        </div>
        <div class="col-md-4">
            <?= $form->field($model, 'farenphone')->textInput(['maxlength' => 255]) ?>
        </div>
        <div class="col-md-4">
            <?= $form->field($model, 'farenemail')->textInput(['maxlength' => 255]) ?>
        </div>
    </div>
    <div class="row">
        <div class="col-md-2">
            <?= $form->field($model, 'yyzhizao')->textInput(['maxlength' => 255]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'zcdizhi')->textInput(['maxlength' => 255]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'qychengli')->textInput(['maxlength' => 255]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'qychenglizhi')->textInput(['qychenglizhi' => 255]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'jyfanwei')->textInput(['jyfanwei' => 255]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'card')->textInput(['maxlength' => 255]) ?>
        </div>
    </div>
    <div class="row">
        <div class="col-md-3">
           <?php
            if(isset(json_decode($model->yyzhizhaoimg)->newname)){
                $img = json_decode($model->yyzhizhaoimg)->newname;
            }else{

                $img = $model->yyzhizhaoimg;
            }
            $siteRoot = Yii::$app->params['qtimg'];
            echo '<label class="control-label">营业执照</label>';
            echo FileInput::widget([
                'model' => $model,
                'attribute' => 'yyzhizhaoimg',
                'options' => ['accept' => 'image/*'],
                'pluginOptions' => [
                    'uploadExtraData' => [
                        'album_id' => 20,
                        'cat_id' => 'Nature'
                    ],
                    'initialPreview'=>[
                        !empty($img)?Html::img(Yii::$app->params['qtimg'].$img):null,
                    ],
                    'initialCaption'=> $img,
                    'maxFileCount' => 10,
                    "showUpload"=> false,
                ]
            ]);
            ?>
        </div>
        <div class="col-md-3">
            <?php
            if(isset(json_decode($model->cardz)->newname)){
                $img = json_decode($model->cardz)->newname;
            }else{

                $img = $model->cardz;
            }
            $siteRoot = Yii::$app->params['qtimg'];
            echo '<label class="control-label">身份证正面</label>';
            echo FileInput::widget([
                'model' => $model,
                'attribute' => 'cardz',
                'options' => ['accept' => 'image/*'],
                'pluginOptions' => [
                    'uploadExtraData' => [
                        'album_id' => 20,
                        'cat_id' => 'Nature'
                    ],
                    'initialPreview'=>[
                        !empty($img)?Html::img(Yii::$app->params['qtimg'].$img):null,
                    ],
                    'initialCaption'=> $img,
                    'maxFileCount' => 10,
                    "showUpload"=> false,
                ]
            ]);
            ?>
        </div>
        <div class="col-md-3">
            <?php
            if(isset(json_decode($model->cardf)->newname)){
                $img = json_decode($model->cardf)->newname;
            }else{

                $img = $model->cardf;
            }
            $siteRoot = Yii::$app->params['qtimg'];
            echo '<label class="control-label">身份证反面</label>';
            echo FileInput::widget([
                'model' => $model,
                'attribute' => 'cardf',
                'options' => ['accept' => 'image/*'],
                'pluginOptions' => [
                    'uploadExtraData' => [
                        'album_id' => 20,
                        'cat_id' => 'Nature'
                    ],
                    'initialPreview'=>[
                        !empty($img)?Html::img(Yii::$app->params['qtimg'].$img):null,
                    ],
                    'initialCaption'=> $img,
                    'maxFileCount' => 10,
                    "showUpload"=> false,
                ]
            ]);
            ?>
        </div>
        <div class="col-md-3">
            <?php
            if(isset(json_decode($model->fwdengjiimg)->newname)){
                $img = json_decode($model->fwdengjiimg)->newname;
            }else{

                $img = $model->fwdengjiimg;
            }
            $siteRoot = Yii::$app->params['qtimg'];
            echo '<label class="control-label">相关资质</label>';
            echo FileInput::widget([
                'model' => $model,
                'attribute' => 'fwdengjiimg',
                'options' => ['accept' => 'image/*'],
                'pluginOptions' => [
                    'uploadExtraData' => [
                        'album_id' => 20,
                        'cat_id' => 'Nature'
                    ],
                    'initialPreview'=>[
                        !empty($img)?Html::img(Yii::$app->params['qtimg'].$img):null,
                    ],
                    'initialCaption'=> $img,
                    'maxFileCount' => 10,
                    "showUpload"=> false,
                ]
            ]);
            ?>
        </div>
    </div>

     <div class="row">
        <div class="col-md-12">
            <?= $form->field($model, 'description')->textInput(['maxlength' => 255]) ?>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <?= $form->field($model,'content')->widget('kucha\ueditor\UEditor',[]);?>
        </div>
    </div>
    
    <?= $form->field($model, 'qiyong')->dropDownList(array('1'=>'启用','2'=>'不启用')) ?>
    <?php 
    if(isset($modelled)){
        foreach($modelled as $key=>$val){ 
            $valname = '';
            $decode = json_decode($model->optiontag,true);
                if($decode){
                $keyiset = array_key_exists($val['name'], $decode);
                    
                if($keyiset){
                    $valname = $decode[$val['name']];
                }
            }
            
            echo  Modelled::createform($val['option'],$val['name'],'tag['.$val['name'].']',  $valname);
        } 
    }

     ?>

    <div class="form-group">
        <?= Html::Button($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary','id'=>"butsub"]) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
<?php $this->beginBlock('footer_scripts'); ?>
    <script>
        $(document).ready(function(){

           $('#butsub').click(function(){
                var username = $("#member-username").val();
                if(!$.trim(username)){
                    alert('用户名不能为空');
                    return false;
                }
                var email = $("#member-email").val();
                if(!$.trim(email)){
                    alert('邮箱不能为空');
                    return false;
                }

                var phone = $("#member-phone").val();
                var reg = /^0?1[3|4|5|7|8][0-9]\d{8}$/;
                var mobile = /^((0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;
                if(!reg.test(phone) && !mobile.test(phone) ){

                    alert("填写电话不正确");
                    return false;
                }

                var xingming = $("#member-xingming").val();
                if(!$.trim(xingming)){
                    alert('姓名不能为空');
                    return false;
                }

                var work = $("#member-work").val();
                if(!$.trim(work)){
                    alert('职务不能为空');
                    return false;
                }

                var company = $("#member-company").val();
                if(!$.trim(company)){
                    alert('企业名称不能为空');
                    return false;
                }

                var address = $("#member-address").val();
                if(!$.trim(address)){
                    alert('企业详细地址不能为空');
                    return false;
                }

                var farentel = $("#member-farentel").val();
                if(!$.trim(farentel)){
                    alert('企业电话不能为空');
                    return false;
                }

                if(!reg.test(farentel) && !mobile.test(farentel) ){

                    alert("企业电话格式不正确");
                    return false;
                }


                var grnum = $("#member-grnum").val();
                if(!$.trim(grnum)){
                    alert('员工人数不能为空');
                    return false;
                }

                var zhucezj = $("#member-zhucezj").val();
                if(!$.trim(zhucezj)){
                    alert('注册资金不能为空');
                    return false;
                }

                var faren = $("#member-faren").val();
                if(!$.trim(faren)){
                    alert('联系人姓名不能为空');
                    return false;
                }

                var farenphone = $("#member-farenphone").val();
                if(!$.trim(farenphone)){
                    alert('联系人电话不能为空');
                    return false;
                }

                var farenemail = $("#member-farenemail").val();
                if(!$.trim(farenemail)){
                    alert('联系人邮箱不能为空');
                    return false;
                }

                var yyzhizao = $("#member-yyzhizao").val();
                if(!$.trim(yyzhizao)){
                    alert('统一社会信用代码不能为空');
                    return false;
                }

                var zcdizhi = $("#member-zcdizhi").val();
                if(!$.trim(zcdizhi)){
                    alert('营业执照所在地不能为空');
                    return false;
                }

                var jyfanwei = $("#member-jyfanwei").val();
                if(!$.trim(jyfanwei)){
                    alert('经营范围不能为空');
                    return false;
                }

                var zhucezj = $("#member-zhucezj").val();
                if(!$.trim(zhucezj)){
                    alert('注册资金不能为空');
                    return false;
                }

                var certificate = $("#member-card").val();
                if(!$.trim(certificate)){
                    alert('证件号码不能为空');
                    return false;
                }


                var reg = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{2}[0-9]([0-9]|X|x)$/;
                if (!reg.test(certificate)) {
                    alert("请填写正确的身份证号");
                    return false;
                }


                var reg_email = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)$/;
                if (!reg_email.test(email)) {
                    alert("请填写正确的邮箱");
                    return false;
                }
                <?php if($model->isNewRecord){ ?>
                var password  = $("#member-password").val();
                if(password.length<6){
                    alert("密码不能小于6位");
                    return false;
                }
                var repassword  = $("#member-repassword").val();
                if(!$.trim(password)){
                    alert("密码不能为空");
                    return false;
                }
                if(password !== repassword){
                    alert("两次密码输入不一致");
                    return false;
                }
                <?php } ?>

                var  res = true;

                if(res){
                    $('#subform').submit();
                }
            })
        });
    </script>
<script>
    $(document).ready(function(){

      <?php  if(!empty($model['loc_province'])){?>

        var province = "<?= $model['loc_province'] ?>";
        var city = "<?= $model['loc_city'] ?>";
        var area = "<?= $model['loc_town'] ?>";

    <?php }else{ ?>

        var province = "省 必选";
        var city =  "市 必选";
        var area =  "区 必选";
    <?php } ?>
    var pcas = new PCAS("province,"+province,"city,"+city,"area,"+area);
    });
</script>
<?php $this->endBlock(); ?>
